﻿using System;
using Communication.Message;

namespace Communication.Channel
{
	// Token: 0x0200001E RID: 30
	public abstract class AbstractChannel : Channel
	{
		// Token: 0x17000004 RID: 4
		// (get) Token: 0x06000117 RID: 279 RVA: 0x0000351E File Offset: 0x0000171E
		// (set) Token: 0x06000118 RID: 280 RVA: 0x00003526 File Offset: 0x00001726
		protected int ChannelState
		{
			get
			{
				return this.channelState;
			}
			set
			{
				this.channelState = value;
			}
		}

		// Token: 0x17000005 RID: 5
		// (get) Token: 0x06000119 RID: 281 RVA: 0x0000352F File Offset: 0x0000172F
		protected object StateLock
		{
			get
			{
				return this.stateLock;
			}
		}

		// Token: 0x0600011A RID: 282 RVA: 0x00003537 File Offset: 0x00001737
		public AbstractChannel()
		{
			this.channelState = AbstractChannel.CHANNEL_STATE_OPEN;
		}

		// Token: 0x0600011B RID: 283
		public abstract void Close();

		// Token: 0x0600011C RID: 284
		public abstract void Connect(Address remoteAddress);

		// Token: 0x0600011D RID: 285
		public abstract void Disconnect();

		// Token: 0x0600011E RID: 286
		public abstract ChannelConfig GetConfig();

		// Token: 0x0600011F RID: 287 RVA: 0x00003558 File Offset: 0x00001758
		public bool IsConnected()
		{
			bool result;
			lock (this.StateLock)
			{
				result = (this.channelState == AbstractChannel.CHANNEL_STATE_CONNECTED);
			}
			return result;
		}

		// Token: 0x06000120 RID: 288 RVA: 0x0000359C File Offset: 0x0000179C
		public bool IsOpen()
		{
			bool result;
			lock (this.StateLock)
			{
				result = (this.channelState == AbstractChannel.CHANNEL_STATE_OPEN);
			}
			return result;
		}

		// Token: 0x06000121 RID: 289
		public abstract void WriteAsync(ChannelMessage message);

		// Token: 0x06000122 RID: 290
		public abstract void WriteSync(ChannelMessage message);

		// Token: 0x06000123 RID: 291 RVA: 0x000035E0 File Offset: 0x000017E0
		public bool IsClosed()
		{
			bool result;
			lock (this.StateLock)
			{
				result = (this.channelState == AbstractChannel.CHANNEL_STATE_CLOSED);
			}
			return result;
		}

		// Token: 0x06000124 RID: 292 RVA: 0x00003624 File Offset: 0x00001824
		public void AddChannelConnectedEventHandler(ChannelConnectedEventHandler handler)
		{
			this.OnChannelConnected = (ChannelConnectedEventHandler)Delegate.Combine(this.OnChannelConnected, handler);
		}

		// Token: 0x06000125 RID: 293 RVA: 0x0000363D File Offset: 0x0000183D
		public void RemoveChannelConnectedEventHandler(ChannelConnectedEventHandler handler)
		{
			this.OnChannelConnected = (ChannelConnectedEventHandler)Delegate.Remove(this.OnChannelConnected, handler);
		}

		// Token: 0x06000126 RID: 294 RVA: 0x00003656 File Offset: 0x00001856
		public void AddChannelClosedEventHandler(ChannelClosedEventHandler handler)
		{
			this.OnChannelClosed = (ChannelClosedEventHandler)Delegate.Combine(this.OnChannelClosed, handler);
		}

		// Token: 0x06000127 RID: 295 RVA: 0x0000366F File Offset: 0x0000186F
		public void RemoveChannelClosedEventHandler(ChannelClosedEventHandler handler)
		{
			this.OnChannelClosed = (ChannelClosedEventHandler)Delegate.Remove(this.OnChannelClosed, handler);
		}

		// Token: 0x06000128 RID: 296 RVA: 0x00003688 File Offset: 0x00001888
		public void AddChannelErrorEventHandler(ChannelErrorEventHandler handler)
		{
			this.OnChannelError = (ChannelErrorEventHandler)Delegate.Combine(this.OnChannelError, handler);
		}

		// Token: 0x06000129 RID: 297 RVA: 0x000036A1 File Offset: 0x000018A1
		public void RemoveChannelErrorEventHandler(ChannelErrorEventHandler handler)
		{
			this.OnChannelError = (ChannelErrorEventHandler)Delegate.Remove(this.OnChannelError, handler);
		}

		// Token: 0x0600012A RID: 298 RVA: 0x000036BA File Offset: 0x000018BA
		protected void NotifyChannelConnectedEvent(Channel channel)
		{
			if (this.OnChannelConnected != null)
			{
				this.OnChannelConnected(channel);
			}
		}

		// Token: 0x0600012B RID: 299 RVA: 0x000036D0 File Offset: 0x000018D0
		protected void NotifyChannelClosedEvent(Channel channel)
		{
			if (this.OnChannelClosed != null)
			{
				this.OnChannelClosed(channel);
			}
		}

		// Token: 0x0600012C RID: 300 RVA: 0x000036E6 File Offset: 0x000018E6
		protected void NotifyChannelErrorEvent(Channel channel, Exception error)
		{
			if (this.OnChannelError != null)
			{
				this.OnChannelError(channel, error);
			}
		}

		// Token: 0x04000038 RID: 56
		private ChannelConnectedEventHandler OnChannelConnected;

		// Token: 0x04000039 RID: 57
		private ChannelClosedEventHandler OnChannelClosed;

		// Token: 0x0400003A RID: 58
		private ChannelErrorEventHandler OnChannelError;

		// Token: 0x0400003B RID: 59
		protected static readonly int CHANNEL_STATE_OPEN = 0;

		// Token: 0x0400003C RID: 60
		protected static readonly int CHANNEL_STATE_CONNECTED = 1;

		// Token: 0x0400003D RID: 61
		protected static readonly int CHANNEL_STATE_CLOSED = 2;

		// Token: 0x0400003E RID: 62
		private int channelState;

		// Token: 0x0400003F RID: 63
		private object stateLock = new object();
	}
}
